"""
MediaPlay 支持播放内容：   
1. 图片，支持GIF
2. 视频 MP4
3. 音频 MP3等

"""
import sys 
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from cgai_al.widgets.SwitchVideoWidget import SwitchVideo


# class TaskThread(QThread):
#     """
#     多线程操作并计数
#     """
#     def __init__(self,parent,audio_path):
#         super(TaskThread, self).__init__()
#         self.parent = parent
#         self.audio_path = audio_path
#         # self.info = {}  # info: {"url":url,"ctype":ctype}

#     # def set_info(self,info):
#     #     self.info = info


#     def run(self):
        
#         self.parent.




class MainWindow(QWidget):

    def __init__(self):
        super(MainWindow,self).__init__()

        self.setStyleSheet("border:0px")
        self.setWindowTitle('无人售货')
        self.main_layout = QHBoxLayout()
        self.main_layout.setMargin(0)
        self.main_layout.setSpacing(0)
        self.left_tool_layout = QVBoxLayout()
        self.left_tool_layout.setMargin(0)
        self.btnA = QPushButton("Play B")
        self.btnA.clicked.connect(self._changeA)
        self.btn = QPushButton("Play B")
        self.btn.clicked.connect(self._change)
        self.btnC = QPushButton("Play Audio")
        self.btnC.clicked.connect(self._change_C)
        self.left_tool_layout.addWidget(self.btnA)
        self.left_tool_layout.addWidget(self.btn)
        self.left_tool_layout.addWidget(self.btnC)
        self.swithvideo = SwitchVideo()
        self.swithAudio = SwitchVideo(0,0)
        self.main_layout.addLayout(self.left_tool_layout)
        self.main_layout.addWidget(self.swithvideo)
        self.main_layout.addWidget(self.swithAudio)
        self.setLayout(self.main_layout)

        self.init_play()

    def init_play(self):
        a1 = r'C:\Users\Admin\Downloads\Video\A.mp4'
        a2 = r'C:\Users\Admin\Desktop\img\dog.jpg'
        a3 = r'C:\Users\Admin\Desktop\gif\pp.gif'
        b = r'C:\Users\Admin\Downloads\Video\B.mp4'
        self.swithvideo.set_video(a1)
        
        self.other_video_win = SwitchVideo(960,1080)
        self.other_video_win.set_video(b)
        self.other_video_win.show()

        
    def _changeA(self):
    
        a = r'C:\Users\Admin\Downloads\Video\A.mp4'
        self.swithvideo.set_video(a)      


    def _change(self):
        
        b = r'C:\Users\Admin\Downloads\Video\B.mp4'
        self.swithvideo.set_video(b)

    def _change_C(self):
        
        a = r'C:\Users\Admin\PyOut\CGAI\ali-tts\tests\test_tts_chuangirl.mp3'
        self.swithAudio.set_video(a)

if __name__ == '__main__':
     app = QApplication(sys.argv)
     window = MainWindow()
     window.show()
     sys.exit(app.exec_())
    